package mogiksaop.qliphoth.client.models.smd;

//import com.pixelmonmod.pixelmon.entities.pixelmon.helpers.animation.IncrementingVariable;
import java.util.ArrayList;
import java.util.List;

import mogiksaop.qliphoth.common.entities.helpers.IncrementingVariable;

public class SmdAnimationSequence {
	List<SmdAnimation> sequence;

	public SmdAnimationSequence(List<SmdAnimation> animations, ValveStudioModel model) {
		this.current = -1;

		this.sequence = new ArrayList();
		animations.forEach(animation -> this.sequence.add(new SmdAnimation(animation, model)));
	}

	int current;

	public SmdAnimation next() {
		this.current++;
		if (this.current >= this.sequence.size())
			this.current = 0;
		if (this.sequence.isEmpty())
			return null;
		return (SmdAnimation) this.sequence.get(this.current);
	}

	public SmdAnimation current() {
		if (this.current < 0)
			this.current = 0;
		if (this.sequence.isEmpty())
			return null;
		return (SmdAnimation) this.sequence.get(this.current);
	}

	public void precalculate(SmdModel body) {
		List<SmdAnimation> precalculated = new ArrayList<SmdAnimation>();
		for (SmdAnimation animation : this.sequence) {
			if (!precalculated.contains(animation)) {
				animation.precalculateAnimation(body);
				precalculated.add(animation);
			}
		}
	}

	public SmdAnimation checkForIncrement(IncrementingVariable variable) {
		SmdAnimation current = current();
		if (this.sequence.size() > 1 && variable.value + variable.increment >= current.totalFrames) {
			variable.value = 0.0F;
			return next();
		}

		return current;
	}

	public SmdAnimation checkForFinalFrame(int frame) {
		if (frame > (current()).totalFrames)
			return next();
		return current();
	}
}